<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>二进制安全地写入 bzip2 文件</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.bzwrite" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">bzwrite</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">bzwrite</span> &mdash; <span class="dc-title">二进制安全地写入 bzip2 文件</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.bzwrite-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>bzwrite</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$bz</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code></span>
  ] ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>bzwrite()</strong></span> 把字符串（string）写入了指定的 bzip2 文件流。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.bzwrite-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">bz</code></dt>

     <dd>

      <p class="para">
       文件指针。它必须是有效的并且指向 <span class="function"><a href="bzopen.html" class="function">bzopen()</a></span> 成功打开的文件。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">data</code></dt>

     <dd>

      <p class="para">
       要写入的数据。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">length</code></dt>

     <dd>

      <p class="para">
       如果提供了这个参数，将仅仅写入 <code class="parameter">length</code>（未压缩）个字节，若 <code class="parameter">data</code> 小于该指定的长度则写入全部数据。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.bzwrite-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回写入的数据字节数，错误时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.bzwrite-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-701">
    <p><strong>Example #1 <span class="function"><strong>bzwrite()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"uncompressed&nbsp;data"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bz&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">bzopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"/tmp/foo.bz2"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">bzwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$bz</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">bzclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$bz</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>
 
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.bzwrite-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="bzread.html" class="function" rel="rdfs-seeAlso">bzread()</a> - bzip2 文件二进制安全地读取</span></li>
    <li class="member"><span class="function"><a href="bzopen.html" class="function" rel="rdfs-seeAlso">bzopen()</a> - 打开 bzip2 压缩文件</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>